home *** CD-ROM | disk | FTP | other *** search
/ NeXT Education Software Sampler 1992 Fall / NeXT Education Software Sampler 1992 Fall.iso / Programming / Source / HippoDraw / hippo / getarg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-28  |  1.7 KB  |  70 lines

  1. /*
  2.  * getarg, iargc - return to Fortran a command line argument
  3.  *
  4.  * Usage:
  5.  *     
  6.  *    character*N c
  7.  *    integer i,j
  8.  *    integer function iargc
  9.  * 
  10.  *          call getarg(i,c)
  11.  *          j = iargc 
  12.  *   
  13.  *    getarg returns the i-th command line argument of the current process,
  14.  *    filled with trailing blanks as needed.
  15.  *    The 0th command line argument is the full
  16.  *      pathname of the application's executable file.
  17.  *
  18.  *    iargc returns the index of the last argument.
  19.  *                              
  20.  * restrictions:                
  21.  *        It is up to the FORTRAN programmer to provide    
  22.  *        a character array that is big enough.            
  23.  *                                                    
  24.  * notes:                                            
  25.  *        The third dummy argument is passed implicitly   
  26.  *        by the compiler. Accessing this argument is     
  27.  *         somewhat C compiler dependent and probably a    
  28.  *        good place to look if this routine stops         
  29.  *        working under a different compiler.    
  30.  *
  31.  * Written for NeXT OS 1.0 by Paul Kunz, SLAC, August 1990
  32.  *
  33.  * Copyright (C) 1990 The Board of Trustees of The Leland Stanford
  34.  * Junior University.  All Rights Reserved.
  35.  *
  36.  */            
  37.  
  38. int iargc( int *dummy )
  39. {
  40.     extern int NXArgc;    /* argc saved in crt0    */
  41.     
  42.     return (NXArgc-1);
  43. }
  44.  
  45. void getarg( iarg, carray, dummy, esize )
  46.  
  47. long *iarg;        /* pointer to fortran integer*4            */
  48. char *carray;    /* pointer to fortran character array    */
  49. int dummy;        /* dummy size for iarg                    */
  50. int esize;        /* size of fortran character array        */
  51.  
  52. {
  53. extern int    NXArgc;        /* argc saved in crt0    */
  54. extern char **NXArgv;        /* argv saved in crt0    */
  55. int i, j;
  56. char *c;
  57.  
  58.     i = *iarg;
  59.     j = esize;
  60.     if ( i >= 0 && i < NXArgc ) {
  61.         c = NXArgv[i];
  62.         while (*c) {    /* copy characters until null    */
  63.             *carray++ = *c++;
  64.             j--;
  65.         }
  66.     }
  67.     for ( ; j > 0 ; j-- )    /* add any trailing blanks needed */
  68.         *carray++ = ' ';
  69. }
  70.